package com.ruoyi.system.controller;

import com.ruoyi.argument.CurrentUser;
import com.ruoyi.dto.DataWrapper;
import com.ruoyi.system.domain.Student;
import com.ruoyi.system.dto.LoginOrRegisterParam;
import com.ruoyi.system.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 学生信息Controller
 *
 * @author ruoyi
 * @date 2023-03-29
 */
@RestController
@RequestMapping("/student")
public class StudentController{

    @Autowired
    private StudentService studentService;


    /**
     * 查询学生信息列表
     *
     * @return
     */
    @PostMapping("/register")
    public DataWrapper<String> register(@RequestBody LoginOrRegisterParam loginOrRegisterParam) {
        this.studentService.register(loginOrRegisterParam);
        return DataWrapper.success();
    }

    @PostMapping("/login")
    public DataWrapper<Object> login(@RequestBody LoginOrRegisterParam loginOrRegisterParam) {
        String token = this.studentService.login(loginOrRegisterParam);
        return DataWrapper.success(token);
    }

    @PostMapping("/mine")
    public DataWrapper<Student> mine(@CurrentUser Student student) {
        return DataWrapper.success(student);
    }
}
